﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class SingleAccordionForm : ItemFormTemplate
    {
        public SingleAccordionForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\SingleAccordionForm\\SingleAccordionForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.Alignment = SingleAccordionAlignments.Left;
            this.demo_control.CategoryNodeStyle.MouseAnimationEnabled = false;
            this.demo_control.CategoryNodeStyle.ImageVisible = false;
            this.demo_control.CategoryNodeStyle.FoldVisible = true;
            this.demo_control.CategoryNodeStyle.FoldArrowsIsInward = true;
            this.demo_control.ContentNodeStyle.MouseAnimationEnabled = true;
            this.demo_control.ContentNodeStyle.ImageVisible = false;

            this.alignment_dropDownListPlus.Multiple = false;
            this.alignment_dropDownListPlus.BindEnumList<SingleAccordionAlignments>(this.demo_control.Alignment);
            this.alignment_dropDownListPlus.SelectedItemsChanged += this.Alignment_dropDownListPlus_SelectedItemsChanged;

            this.categoryLRAnimationEnabled_toggleSwitch.IsOn = this.demo_control.CategoryNodeStyle.MouseAnimationEnabled;
            this.categoryLRAnimationEnabled_toggleSwitch.Toggled += this.CategoryLRAnimationEnabled_toggleSwitch_Toggled;

            this.categoryImageVisible_toggleSwitch.IsOn = this.demo_control.CategoryNodeStyle.ImageVisible;
            this.categoryImageVisible_toggleSwitch.Toggled += this.CategoryImageVisible_toggleSwitch_Toggled;

            this.categoryFoldVisible_toggleSwitch.IsOn = this.demo_control.CategoryNodeStyle.FoldVisible;
            this.categoryFoldVisible_toggleSwitch.Toggled += this.CategoryFoldVisible_toggleSwitch_Toggled;

            this.categoryFoldArrowsIsInward_toggleSwitch.IsOn = this.demo_control.CategoryNodeStyle.FoldArrowsIsInward;
            this.categoryFoldArrowsIsInward_toggleSwitch.Toggled += this.CategoryFoldArrowsIsInward_toggleSwitch_Toggled;

            this.contentLRAnimationEnabled_toggleSwitch.IsOn = this.demo_control.ContentNodeStyle.MouseAnimationEnabled;
            this.contentLRAnimationEnabled_toggleSwitch.Toggled += this.ContentLRAnimationEnabled_toggleSwitch_Toggled;

            this.contentImageVisible_toggleSwitch.IsOn = this.demo_control.ContentNodeStyle.ImageVisible;
            this.contentImageVisible_toggleSwitch.Toggled += this.ContentImageVisible_toggleSwitch_Toggled;

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void Alignment_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.Alignment = (SingleAccordionAlignments)control.SelectedItem.Tag;
        }

        private void CategoryLRAnimationEnabled_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.CategoryNodeStyle.MouseAnimationEnabled = control.IsOn;
        }

        private void CategoryImageVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.CategoryNodeStyle.ImageVisible = control.IsOn;
        }

        private void CategoryFoldVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.CategoryNodeStyle.FoldVisible = control.IsOn;
        }

        private void CategoryFoldArrowsIsInward_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.CategoryNodeStyle.FoldArrowsIsInward = control.IsOn;
        }

        private void ContentLRAnimationEnabled_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.ContentNodeStyle.MouseAnimationEnabled = control.IsOn;
        }

        private void ContentImageVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.ContentNodeStyle.ImageVisible = control.IsOn;
        }

        #endregion

    }
}
